#include "StdAfx.h"
#include "AIEntityControlStub.h"


AIEntityControlStub::AIEntityControlStub(EntityControl * entity)
{
	//controller  = NULL;

	setupParameters();

	parameterMap[POSITION_PARAMETER]->setValue(entity->getParameter(POSITION_PARAMETER)->getValue());
	parameterMap[HITPOINT_PARAMETER]->setValue(entity->getParameter(HITPOINT_PARAMETER)->getValue());
	parameterMap[KILLED_PARAMETER]->setValue(entity->getParameter(KILLED_PARAMETER)->getValue());
	parameterMap[SPEED_PARAMETER]->setValue(entity->getParameter(SPEED_PARAMETER)->getValue());
	parameterMap[LOOKAT_PARAMETER]->setValue(entity->getParameter(LOOKAT_PARAMETER)->getValue());
	parameterMap[MAP_WAYPOINT_PARAMETER]->setValue(entity->getParameter(MAP_WAYPOINT_PARAMETER)->getValue());

	

}


AIEntityControlStub::AIEntityControlStub(AIEntityControlStub * entity)
{
	//controller = NULL;

	parameterMap[POSITION_PARAMETER] = new VectorEntityParameter(POSITION_PARAMETER);
	parameterMap[HITPOINT_PARAMETER] = new IntEntityParameter(HITPOINT_PARAMETER);
	parameterMap[KILLED_PARAMETER] = new CustomEntityParameter<bool>(KILLED_PARAMETER);
	parameterMap[SPEED_PARAMETER] = new IntEntityParameter(SPEED_PARAMETER);
	parameterMap[LOOKAT_PARAMETER] = new VectorEntityParameter(LOOKAT_PARAMETER);
	parameterMap[MAP_WAYPOINT_PARAMETER] = new IntEntityParameter(MAP_WAYPOINT_PARAMETER);


	parameterMap[POSITION_PARAMETER]->setValue(entity->getParameter(POSITION_PARAMETER)->getValue());
	parameterMap[HITPOINT_PARAMETER]->setValue(entity->getParameter(HITPOINT_PARAMETER)->getValue());
	parameterMap[KILLED_PARAMETER]->setValue(entity->getParameter(KILLED_PARAMETER)->getValue());
	parameterMap[SPEED_PARAMETER]->setValue(entity->getParameter(SPEED_PARAMETER)->getValue());
	parameterMap[LOOKAT_PARAMETER]->setValue(entity->getParameter(LOOKAT_PARAMETER)->getValue());
	parameterMap[MAP_WAYPOINT_PARAMETER]->setValue(entity->getParameter(MAP_WAYPOINT_PARAMETER)->getValue());

	TriggerList = entity->getTriggerList();
	listenerMap = entity->getListenerMap();
	dirtyTriggers = entity->getDirtyTriggerList();
	newDirtyTriggers = entity->getNewDirtyTriggerList();

}


AIEntityControlStub::~AIEntityControlStub(void)
{
}

void  AIEntityControlStub::killEntity()
{
	CustomEntityParameter<bool> newParam = CustomEntityParameter<bool>(KILLED_PARAMETER);
	newParam.setCustomValue((void*)true);
	setParameter(KILLED_PARAMETER, &newParam);
}

void AIEntityControlStub::setPosition(Ogre::Vector3 pos)
{
	

	VectorEntityParameter newParam = VectorEntityParameter(POSITION_PARAMETER);
	newParam.setVectorValue(pos);
	
	setParameter(POSITION_PARAMETER, &newParam);
}

Ogre::Vector3 AIEntityControlStub::getPosition()
{

	return *(Ogre::Vector3*)getParameter(POSITION_PARAMETER)->getValue();

}

void AIEntityControlStub::setLookAt(Ogre::Vector3 pos)
{
	

	parameterMap[LOOKAT_PARAMETER]->setValue((void*)&pos);


}


std::vector<Trigger*>* AIEntityControlStub::checkSatisfiedTriggers()
{
	satTriggerList.clear();

	for(std::vector<Trigger*>::iterator i =dirtyTriggers.begin(); i!= dirtyTriggers.end(); i++)
	{
		if((*i)->CheckReq(this))
		{
			satTriggerList.push_back(*i);
			(*i)->setDirty(this);
		}
		


	}

	dirtyTriggers.clear();
	

	return &satTriggerList;
}


void AIEntityControlStub::fireTrigger(Trigger * trigger)
{
	trigger->FireTrigger(this);

	
	/*for(int i =	0; i< newDirtyTriggers.size(); i++)
	{

		dirtyTriggers.push_back(newDirtyTriggers[i]);

	}*/
	dirtyTriggers.clear();
	dirtyTriggers.swap(newDirtyTriggers);
}
